package com.djbx.points.common.core.utils.lock.impl;

import com.djbx.points.common.core.utils.lock.ILock;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * 〈lock创建工厂〉
 *
 * @author sader
 * @date 2021/11/26
 * @since 1.0.0
 */
@Slf4j
public abstract class SimpleLock {

   public static final String REDISSON_CLIENT = "org.redisson.Redisson";

   private SimpleLock() {}

   public static ILock getLock(Object lockClient, String key){
      if(StringUtils.isBlank(key) || lockClient == null){
         log.error("arguments cannot be null");
         return null;
      }

      ILock lock = null;
      String name = lockClient.getClass().getName();
      if (REDISSON_CLIENT.equals(name)) {
         lock = new RedissionLock(lockClient, key);
      } else {
         log.warn("unkown lock type");
      }
      return lock;
   }
}
